package spring.boot.fastdep.jwt.common;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import lombok.Data;

import java.io.Serializable;

/**
 * 接口返回通用封装
 */
@Data
@JsonPropertyOrder({"code", "msg", "data"})
public class Results<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    private int code;
    private String msg;
    private T data;

    private Results() {
    }

    private Results(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    private Results(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    //=======================================================================================================

    /**
     * 成功code
     */
    private static final int SUCCESS_CODE = 200;

    /**
     * 成功 msg
     */
    private static final String SUCCESS_MSG = "SUCCESS";

    public static Results success() {
        return new Results(SUCCESS_CODE, SUCCESS_MSG);
    }

    public static Results success(String msg) {
        return new Results(SUCCESS_CODE, msg);
    }

    public static Results success(Object data) {
        return new Results(SUCCESS_CODE, SUCCESS_MSG, data);
    }

    //=======================================================================================================

    /**
     * 手机号已经注册
     */
    private static final int HAD_REG_MOBILE_ERROR_CODE = 201;

    public static Results mobileHadRegError(String message) {
        return new Results(HAD_REG_MOBILE_ERROR_CODE, message);
    }

    //=======================================================================================================

    /**
     * 手机号尚未注册
     */
    private static final int MOBILE_NOT_REG_ERROR_CODE = 202;

    public static Results mobileNotRegError(String message) {
        return new Results(MOBILE_NOT_REG_ERROR_CODE, message);
    }

    //=======================================================================================================


    /**
     * 参数错误 code
     */
    private static final int PARAM_ERROR_CODE = 203;

    public static Results paramError(String message) {
        return new Results(PARAM_ERROR_CODE, message);
    }

    //=======================================================================================================


    /**
     * 验证码发送失败 code
     */
    private static final int SMS_CODE_SEND_FAIL_ERROR_CODE = 204;

    public static Results smsCodeSendFailError(String message) {
        return new Results(SMS_CODE_SEND_FAIL_ERROR_CODE, message);
    }

    //=======================================================================================================


    /**
     * 验证码发送过于频繁 code
     */
    private static final int SMS_CODE_SEND_TOO_MUCH_ERROR_CODE = 205;


    public static Results smsCodeSendTooMuchError(String message) {
        return new Results(SMS_CODE_SEND_TOO_MUCH_ERROR_CODE, message);
    }
}
